<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
	</head>
	<body>
		<script>
			let arr = ['red', 'blue', 'green', 'darkgreen'];

			arr.forEach(function (value) {
				if (value === 'green') {
					console.log('found');
					return true; // forEach 里的 return 不会终止遍历
				}
				console.log('vae');
			});

			// 如果查询数组中唯一的元素，用 some 方法更合适
			arr.some(function (value) {
				if (value === 'green') {
					console.log('found');
					return true; // some 里的 return 会直接终止遍历 迭代效率更高
				}
				console.log('vae');
			});

			arr.filter(function (value) {
				if (value === 'green') {
					console.log('found');
					return true; // filter 里的 return 不会终止遍历
				}
				console.log('vae');
			});
		</script>
	</body>
</html>
